<?php
// ==============PHP 快速排序==============
header("Content-type:text/html;charset=utf-8"); 
$arr = array(9,3,11,23,90,99,12,34,22,87,32); 
echo "<pre>";
print_r(quick_sort($arr));
echo "</pre>";

function quick_sort($array) {
 if(count($array) <= 1) return $array;
 $key = $array[0];
 $rightArray = array();
 $leftArray = array();
 for($i = 1; $i < count($array); $i++) {
    if($array[$i] >= $key) {
          $rightArray[] = $array[$i];
    } else {
        $leftArray[] = $array[$i];
    }
 }
 $leftArray = quick_sort($leftArray);
 $rightArray = quick_sort($rightArray);
 return array_merge($leftArray, array($key), $rightArray);
}